package com.lovo.order.dao;

import com.lovo.order.dto.OrderDto;
import com.lovo.order.entity.OrderEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.Map;

public interface IOrderDao extends CrudRepository<OrderEntity,Long> {

    @Query(value = "select new map(u.userName,o.orderNumber,o.goodsNames,o.priceSum) "+
            " from OrderEntity o left join o.user u where o.priceSum>=?1 and o.priceSum<=?2 and u.userName=?3",
            countQuery = "select count(o.orderId) " +
                   " from OrderEntity o left join o.user u where o.priceSum>=?1 and o.priceSum<=?2 and u.userName=?3")
    public Page<Map> pagesOrder(float startPrice, float endPrice,String userName, PageRequest pageRequest);
}
